/*
user.controller('userController', function(
	$scope, $http, $state, $stateParams, $timeout, $log, userService, adminService
) {
	

});
*/
var userController = {} ;


userController.list = function($rootScope, $scope, $state, $log, ngDialog, userService, hello) {
	//hello.aa();
	
	$scope.toastrTest = function() {
		toastr.error('s', {timeOut: 50000, closeButton: true, progressBar: true})
	}
	
	$scope.onDelete = function() {
		ngDialog.open({
		    preCloseCallback: function(value) {
		        if (confirm('Are you sure you want to close without saving your changes?')) {
		        	alert('删除成功');
		            return true;
		        }
		        return false;
		    }
		});
	}
	
	$scope.userlist = {} ;
	$scope.gridOptions = {
		paginationPageSizes: [5, 10, 25],
     	paginationPageSize: 5
	} ;
	$scope.gridOptions.columnDefs = [
		{field: 'id'},
		{field: 'account'},
		{field: 'password'},
		{field: 'birthday'},
		{field: 'contact.email'},
		{field: 'contact.mobile'},
		{field: 'createTime'},
		{field: 'remark'}
	];
	
	userService.selectUserList().then(function(result){
		$scope.gridOptions.data = result.list ;
		$scope.userlist = result ;
 	}, function(result) {
		console.info(result) ;
	});
	
	
	var getUsers = function() {
		var currentPage = $scope.paginationConf.currentPage;
		var itemsPerPage = $scope.paginationConf.itemsPerPage;
		userService.selectUserList2(ngDialog, currentPage, itemsPerPage).then(function(result){
			$scope.userlist2 = result ;
			$scope.paginationConf.totalItems = result.total;
			
		}, function(error) {
			
		});
	}
	// 配置分页基本参数
    $scope.paginationConf = {
        currentPage: 1,
        itemsPerPage: 5,
        pagesLength: 8,
		perPageOptions: [10, 20, 30, 40, 50]
    };
        
	$scope.$watch('paginationConf.currentPage + paginationConf.itemsPerPage', getUsers);
};

userController.add = function($rootScope, $scope, $state, $log, ngDialog, userService) {
	ngDialog.open({
	    template: '<img src="/hake-ui/framework/vendors/pageloader/images/loader1.GIF">',
	    plain: true,
	    showClose: false,
        closeByDocument: true,
        closeByEscape: false,
	    width: 500,
	    height: 200,
	});
	$scope.onSave = function(isValid) {
		
		if(!isValid) {
			alert("数据不正确");
		} else {
			userService.add($scope.fdata).then(function(result){
				console.info(result) ;
				toastr.success('操作成功');
				$state.go('admin.user.list');
			}, function(result) {
				console.info(result) ;
				toastr.error('操作失败');
			});
		}
	}
	
}

